package com.glory.gloryquickui.utils;//
// Source code recreated from a .class file by IntelliJ IDEA
// (powered by FernFlower decompiler)
//



import android.content.Context;
import android.text.Editable;
import android.text.TextWatcher;
import android.view.KeyEvent;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.view.View.OnClickListener;
import android.widget.TextView;
import android.widget.TextView.OnEditorActionListener;

import com.glory.gloryquickui.R;
import com.glory.gloryquickui.widget.dialog.FreeUI_GeneralFragmentDialog;
import com.glory.gloryquickui.widget.dialog.callback.FreeUI_CommonCallback;
import com.glory.gloryquickui.widget.dialog.callback.FreeUI_TextCallback;
import com.glory.gloryquickui.widget.edit.ClearEditText;

public class DialogUtils {
    public DialogUtils() {
    }

    public static FreeUI_GeneralFragmentDialog getFreeDialog(View contentView) {
        FreeUI_GeneralFragmentDialog freeUI_generalFragmentDialog = new FreeUI_GeneralFragmentDialog();
        freeUI_generalFragmentDialog.setLayout(contentView);
        return freeUI_generalFragmentDialog;
    }

    public static FreeUI_GeneralFragmentDialog getConfirmAndCancelDialog(Context context, String tips, final FreeUI_CommonCallback confirmCallback, final FreeUI_CommonCallback cancelCallback) {
        final FreeUI_GeneralFragmentDialog freeUI_generalFragmentDialog = new FreeUI_GeneralFragmentDialog();
        View contentView = LayoutInflater.from(context).inflate(getResID(), (ViewGroup)null);
        TextView tvCancel = (TextView)contentView.findViewById(R.id.tvCancel);
        TextView tvConfirm = (TextView)contentView.findViewById(R.id.tvConfirm);
        TextView tvTips = (TextView)contentView.findViewById(R.id.tvTips);
        tvTips.setText(tips);
        tvCancel.setOnClickListener(new OnClickListener() {
            public void onClick(View v) {
                cancelCallback.onSuccess();
                freeUI_generalFragmentDialog.dismiss();
            }
        });
        tvConfirm.setOnClickListener(new OnClickListener() {
            public void onClick(View v) {
                confirmCallback.onSuccess();
                freeUI_generalFragmentDialog.dismiss();
            }
        });
        freeUI_generalFragmentDialog.setLayout(contentView);
        return freeUI_generalFragmentDialog;
    }

    public static FreeUI_GeneralFragmentDialog getConfirmAndCancelDialog(Context context, String confirm, String cancel, String tips, final FreeUI_CommonCallback confirmCallback, final FreeUI_CommonCallback cancelCallback) {
        final FreeUI_GeneralFragmentDialog freeUI_generalFragmentDialog = new FreeUI_GeneralFragmentDialog();
        View contentView = LayoutInflater.from(context).inflate(getResID(), (ViewGroup)null);
        TextView tvCancel = (TextView)contentView.findViewById(R.id.tvCancel);
        TextView tvConfirm = (TextView)contentView.findViewById(R.id.tvConfirm);
        TextView tvTips = (TextView)contentView.findViewById(R.id.tvTips);
        tvTips.setText(tips);
        tvCancel.setText(cancel);
        tvConfirm.setText(confirm);
        tvCancel.setOnClickListener(new OnClickListener() {
            public void onClick(View v) {
                cancelCallback.onSuccess();
                freeUI_generalFragmentDialog.dismiss();
            }
        });
        tvConfirm.setOnClickListener(new OnClickListener() {
            public void onClick(View v) {
                confirmCallback.onSuccess();
                freeUI_generalFragmentDialog.dismiss();
            }
        });
        freeUI_generalFragmentDialog.setLayout(contentView);
        return freeUI_generalFragmentDialog;
    }

    public static FreeUI_GeneralFragmentDialog getConfirmDialog(Context context, String confirm, String tips, final FreeUI_CommonCallback confirmCallback) {
        final FreeUI_GeneralFragmentDialog freeUI_generalFragmentDialog = new FreeUI_GeneralFragmentDialog();
        View contentView = LayoutInflater.from(context).inflate(getResID(), (ViewGroup)null);
        TextView tvCancel = (TextView)contentView.findViewById(R.id.tvCancel);
        TextView tvConfirm = (TextView)contentView.findViewById(R.id.tvConfirm);
        TextView tvTips = (TextView)contentView.findViewById(R.id.tvTips);
        tvTips.setText(tips);
        tvCancel.setVisibility(View.GONE);
        tvConfirm.setText(confirm);
        tvConfirm.setOnClickListener(new OnClickListener() {
            public void onClick(View v) {
                confirmCallback.onSuccess();
                freeUI_generalFragmentDialog.dismiss();
            }
        });
        freeUI_generalFragmentDialog.setLayout(contentView);
        return freeUI_generalFragmentDialog;
    }

    public static int getResID() {
//        int resID = 0;
//        if (InitUtils.Companion.CURRENT_THEME != FreeApi_StaticMembers.THEME_DARK_GOLD && FreeApi_StaticMembers.CURRENT_THEME != FreeApi_StaticMembers.THEME_SINGLE_DARK_GOLD) {
//            if (FreeApi_StaticMembers.CURRENT_THEME != FreeApi_StaticMembers.THEME_SKY_BLUE && FreeApi_StaticMembers.CURRENT_THEME != FreeApi_StaticMembers.THEME_SINGLE_SKY_BLUE) {
//                if (FreeApi_StaticMembers.CURRENT_THEME == FreeApi_StaticMembers.THEME_GLORY || FreeApi_StaticMembers.CURRENT_THEME == FreeApi_StaticMembers.THEME_SINGLE_GLORY) {
//                    resID = R.layout.free_ui_golry_dialog_with_confirm_and_cancel;
//                }
//            } else {
//                resID =
//            }
//        } else {
//            resID = R.layout.free_ui_dark_dialog_with_confirm_and_cancel;
//        }

        return R.layout.dialog_with_confirm_and_cancel;
    }

    public static FreeUI_GeneralFragmentDialog getScanDialog(final Context context, String tips, final FreeUI_TextCallback editTextScanCallback) {
        final FreeUI_GeneralFragmentDialog freeUI_generalFragmentDialog = new FreeUI_GeneralFragmentDialog();
        View contentView = LayoutInflater.from(context).inflate(getResID(), (ViewGroup)null);
        TextView tvCancel = (TextView)contentView.findViewById(R.id.tvCancel);
        TextView tvConfirm = (TextView)contentView.findViewById(R.id.tvConfirm);
        TextView tvTips = (TextView)contentView.findViewById(R.id.tvTips);
        final ClearEditText etScan = contentView.findViewById(R.id.etScan);
        tvTips.setVisibility(View.GONE);
        etScan.setVisibility(View.VISIBLE);
        etScan.setHint(tips);
        etScan.setOnEditorActionListener(new OnEditorActionListener() {
            public boolean onEditorAction(TextView v, int actionId, KeyEvent event) {
                return event != null && event.getKeyCode() == 66;
            }
        });
        etScan.addTextChangedListener(new TextWatcher() {
            public void beforeTextChanged(CharSequence s, int start, int count, int after) {
            }

            public void onTextChanged(CharSequence s, int start, int before, int count) {
                if (start == 0 && before == 0 && count > 1) {
                    if (s.length() > 0) {
                        editTextScanCallback.onSuccess(s.toString());
                    } else {
                        FreeApi_ToastUtils.showFreeToast("输入信息有误", context, false, 0);
                    }
                }

            }

            public void afterTextChanged(Editable s) {
            }
        });
        tvCancel.setOnClickListener(new OnClickListener() {
            public void onClick(View v) {
                freeUI_generalFragmentDialog.dismiss();
            }
        });
        tvConfirm.setOnClickListener(new OnClickListener() {
            public void onClick(View v) {
                if (etScan.getText().toString().trim().length() > 0) {
                    editTextScanCallback.onSuccess(etScan.getText().toString().trim());
                } else {
                    FreeApi_ToastUtils.showFreeToast("输入信息有误", context, false, 0);
                }

            }
        });
        freeUI_generalFragmentDialog.setLayout(contentView);
        return freeUI_generalFragmentDialog;
    }

    public static FreeUI_GeneralFragmentDialog getScanDialog(final Context context, String tips, String text, final FreeUI_TextCallback editTextScanCallback) {
        final FreeUI_GeneralFragmentDialog freeUI_generalFragmentDialog = new FreeUI_GeneralFragmentDialog();
        View contentView = LayoutInflater.from(context).inflate(getResID(), (ViewGroup)null);
        TextView tvCancel = (TextView)contentView.findViewById(R.id.tvCancel);
        TextView tvConfirm = (TextView)contentView.findViewById(R.id.tvConfirm);
        TextView tvTips = (TextView)contentView.findViewById(R.id.tvTips);
        final ClearEditText etScan = contentView.findViewById(R.id.etScan);
        tvTips.setVisibility(View.GONE);
        etScan.setVisibility(View.VISIBLE);
        etScan.setHint(tips);
        etScan.setText(text);
        etScan.setOnEditorActionListener(new OnEditorActionListener() {
            public boolean onEditorAction(TextView v, int actionId, KeyEvent event) {
                return event != null && event.getKeyCode() == 66;
            }
        });
        etScan.addTextChangedListener(new TextWatcher() {
            public void beforeTextChanged(CharSequence s, int start, int count, int after) {
            }

            public void onTextChanged(CharSequence s, int start, int before, int count) {
                if (start == 0 && before == 0 && count > 1) {
                    if (s.length() > 0) {
                        editTextScanCallback.onSuccess(s.toString());
                    } else {
                        FreeApi_ToastUtils.showFreeToast("输入信息有误", context, false, 0);
                    }
                }

            }

            public void afterTextChanged(Editable s) {
            }
        });
        tvCancel.setOnClickListener(new OnClickListener() {
            public void onClick(View v) {
                freeUI_generalFragmentDialog.dismiss();
            }
        });
        tvConfirm.setOnClickListener(new OnClickListener() {
            public void onClick(View v) {
                if (etScan.getText().toString().trim().length() > 0) {
                    editTextScanCallback.onSuccess(etScan.getText().toString().trim());
                } else {
                    FreeApi_ToastUtils.showFreeToast("输入信息有误", context, false, 0);
                }

            }
        });
        freeUI_generalFragmentDialog.setLayout(contentView);
        return freeUI_generalFragmentDialog;
    }
}
